this.screenshotPreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");								 
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#screenshot").remove();
    });	
	$("a.screenshot").mousemove(function(e){
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


$(document).ready(function() {    
    
    // --- Hide Image ---
    $( '#ajaxLoadAni' ).fadeOut( 'slow' );
    
    // --- Calendar Function ---
    $( ".datepicker" ).datepicker({
            changeMonth: true,
            changeYear: true,
            yearRange:"1995:y"
    });
	
	 $( ".birthdate" ).datepicker({
            changeMonth: true,
            changeYear: true,
            yearRange:"-100y:y",
			defaultDate:"y-m-d"
    });
    
    $( ".datepicker2" ).datepicker({
            changeMonth: true,
            changeYear: true,
            minDate: "-15y",
            maxDate: "y"
    });
	
	$( ".datepicker_books" ).datepicker({
      changeMonth: true,
      changeYear: true,
	   yearRange: "-40:+0"
    });
	
    $( ".datepicker-payment" ).datepicker({
		changeMonth: true
    });	
	
    
	$( ".datepicker3" ).datepicker({
            changeMonth: true,
            changeYear: true,
        });
	
    // --- Accordion Function ---
    $('.accordion h3.head').click(function() {
        $(this).next().slideToggle('slow');
        return false;
    });
	
	$('.accordion h3.head2').click(function(){
		$('ul.head2 li').slideToggle('slow')
        return false;
    });
    
    // --- Student Stat ---
    $( '.studentStat' ).click(function(){
        var a = $('input[name=student_status]:checked').val();
        if(a=='new')
        {
            $('input[name=student_id]').val('');
            $('#studentId').css({ "display" : "none" });
        }
        else
        {
            $('#studentId').css({ "display" : "block" });
        }
    });
    
    // --- Modal ---
    $( '#msgDialog' ).dialog({
		draggable:false,
        autoOpen: false,
		resizable: false,
		height:400,
		modal: true,
        buttons: {
            'Ok': function() {
                $( this ).dialog( 'close' );
            }
        }
    });
    
    // --- Tab ---
    // Tabs
    $('#tabs').tabs();
    
    // --- Get The Base URL ---
    var baseurl = $('#baseurl').val();    
    
    // --- Confirm Deletion ---
    $( 'a.confirm' ).click(function(e){
		
        e.preventDefault();
        var theHREF = $(this).attr("href");
		var title = $(this).attr("title");
        if(!title ){
			$( '#msgDialog > p' ).html( 'Are You Sure?' );
		}else{
			$( '#msgDialog > p' ).html( title );
		}
        $( '#msgDialog' ).dialog( 'option', 'title', 'Confirm' );
        $("#msgDialog").dialog('option', 'buttons', {
                "Confirm" : function() {
						window.location.href = theHREF;
                    },
                "Cancel" : function() {
						$(this).dialog("close");
                    }
                });
		
		$("#msgDialog").dialog("open");
		$('.ui-dialog-buttonpane').find('button').addClass('btn btn-mini btn-primary');

    });
	
	    $( 'a.confirm_blank' ).click(function(e){
            //$( '#msgDialog > p' ).html( 'Are You Sure?' );
            //$( '#msgDialog' ).dialog( 'option', 'title', 'Success' ).dialog( 'open' );
            //alert('here');
        e.preventDefault();
        var theHREF = $(this).attr("href");
		var title = $(this).attr("title");
        if(!title ){
			$( '#msgDialog > p' ).html( 'Are You Sure?' );
		}else{
			$( '#msgDialog > p' ).html( title );
		}
        $( '#msgDialog' ).dialog( 'option', 'title', 'Confirm' );
        $("#msgDialog").dialog('option', 'buttons', {
                "Confirm" : function() {
                    window.location = theHREF;
                    },
                "Cancel" : function() {
                    $(this).dialog("close");
                    }
                });
		
		$("#msgDialog").dialog("open");
		
    });
    
    // --- Create Subject To Curriculum Record ---
    $( '.subject_to_curriculum' ).click(function(){        
            
            $( '#ajaxLoadAni' ).fadeIn( 'slow' );
            
            var target = $(this).attr("id");
            
            $.ajax({
                dataType : 'json',
                url: baseurl + 'admin/create_subject_to_curriculum',
                type: 'POST',
                data: $( '#myform' + target ).serialize(),
                
                success: function( response ) {
                    
                        $( '#msgDialog > p' ).html( 'inserted' );
                        $( '#msgDialog' ).dialog( 'option', 'title', 'Success' ).dialog( 'open' );
                        $( '#ajaxLoadAni' ).fadeOut( 'slow' );
                        
                    
                }

            });
            
            return false;
        
    });
	
	// CHECK ALL CHECKBOXES
	$('.check_all').click(function(){
		
		var id = $(this).attr('id');
		
		if($(this).is(':checked')){
			$('.'+id).attr('checked', 'checked');
		}
		else if($(this).not(':checked')){
			$('.'+id).removeAttr('checked');
		}
	});

	$('.time').timepicker({
		hourGrid: 4,
		minuteGrid: 10,
		timeFormat: 'hh:mm tt'
	});

	//function confirm-auto start
	$( 'a.confirm-auto' ).click(function(e){
			e.preventDefault();
			$('body').addClass('disable_scroll');
			$(this).addClass('current_pick');
			
			var theHREF = $(this).attr("href");
			var title = $(this).attr("title");
			if(!title ){
				$( '#msgDialog > p' ).html( 'Are You Sure?' );
			}else{
				$( '#msgDialog > p' ).html( title );
			}
			$('#msgDialog' ).dialog( 'option', 'title', 'Confirm Action' );
			$('#msgDialog' ).dialog( {
				resizable: false,
				height:140,
				modal: true
			});
			
			$("#msgDialog").dialog('option', 'buttons', {
					"Confirm" : function() {
						$('body').removeClass('disable_scroll');
						$(this).dialog("close");
							$.ajax({
									type: 'POST',
									url: theHREF,
									data:{
										'jquery' : true
									},
									beforeSend: function() {
										$('body').addClass('disable_scroll');
										$('#loader').show();
									},
									 complete: function(){
										$('body').removeClass('disable_scroll');
										$('#loader').hide('slow');
									},
									success: function(msg){
										if(msg == 'true')
										{
											alert("Process was successfully Done");
											$('a.current_pick').parents('tr.profile_box').hide(2000);
										}else{
											alert("Process encountered an error");
										}
									},
									error: function (msg){
										alert("An error has occured");
									}
							});
						},
					"Cancel" : function() {
						$('body').removeClass('disable_scroll');
						$(this).dialog("close");
						}
			});

			$("#msgDialog").dialog("open");
    });

	$('#fee').change(function(){
		var url = $(this).attr('url');
		var opt = $(this).val();
		if(opt == 'is_registration_fee' || opt == 'is_tuition_fee')
		{
			$.get(url, function(data) {
			  $('.dynamic-dropdown').html(data).show(50);
			});
		}else{
			$('.dynamic-dropdown').hide(50);
		
		}
	});
	
	screenshotPreview();
	
	
});// --- end document ready ---


